import torch.utils.data
import torchvision.datasets
from torch.utils.tensorboard import SummaryWriter

dataset = torchvision.datasets.CIFAR10("datasets", train=False, transform=torchvision.transforms.ToTensor(), download=True)
dataloader = torch.utils.data.DataLoader(dataset=dataset, batch_size=64, drop_last=False)

class AdamModule(torch.nn.Module):

    def __init__(self):
        super().__init__()
        self.conv2d = torch.nn.Conv2d(in_channels=3, out_channels=3, kernel_size=3, stride=1, padding=0)

    def forward(self, input):
        return self.conv2d(input)

writer = SummaryWriter("logs")

module = AdamModule()
step = 0
for imgs, target in dataloader:
    output = module(imgs)
    # torch.Size([64, 3, 32, 32])
    writer.add_images("nn_conv2d_input", imgs, step)
    # torch.Size([64, 6, 30, 30])  ->  (x, 3, 30, 30)
    writer.add_images("nn_conv2d_output", output, step)
    # writer.add_images("nn_conv2d_output", torch.reshape(output, (-1, 3, 30, 30)), step)
    step = step + 1

print("success")